﻿cmake_minimum_required(VERSION 3.29)
project(ScreenLock VERSION 1.0.0.0)
message(STATUS "Project Version: ${PROJECT_VERSION}")

# 设置 C++ 标准
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置包含的头文件目录
include_directories(include)

# 生成版本资源文件
configure_file(${CMAKE_SOURCE_DIR}/src/version.rc.in ${CMAKE_SOURCE_DIR}/src/version.rc)

# 添加可执行文件
add_executable(screen_lock
        include/screen_lock.h
        src/main.cpp
        src/screen_lock.cpp
        src/version.rc
)

# 链接选项
target_link_libraries(screen_lock user32.lib)

# 定义 PROJECT_VERSION 预处理器宏
target_compile_definitions(screen_lock PRIVATE PROJECT_VERSION=${PROJECT_VERSION})


# 设置架构名称后缀
message(STATUS "CMAKE_GENERATOR_PLATFORM: ${CMAKE_GENERATOR_PLATFORM}")
if (CMAKE_GENERATOR_PLATFORM STREQUAL "Win32")
    set(ARCH_SUFFIX "x86")
elseif (CMAKE_GENERATOR_PLATFORM STREQUAL "x64")
    set(ARCH_SUFFIX "x64")
else ()
    set(ARCH_SUFFIX "Unknown")
endif ()
set(FINAL_OUT_NAME "ScreenLock_${ARCH_SUFFIX}_v${PROJECT_VERSION}_$<CONFIG>")
message(STATUS "Target output name: ${FINAL_OUT_NAME}.exe")

# 设置 CMAKE 属性 - 输出名称
set_target_properties(screen_lock PROPERTIES OUTPUT_NAME ${FINAL_OUT_NAME})

# 自定义命令：清理并复制生成的二进制文件
add_custom_command(TARGET screen_lock POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_SOURCE_DIR}/build
        COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:screen_lock> ${CMAKE_SOURCE_DIR}/build
)